
package com.hlkj.pay.app.merchant.ext.impl.haike.handler;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.hlkj.framework.caches.service.RedisTemplateService;
import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.id.IdUtils;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.app.common.impl.UploadServiceImpl;
import com.hlkj.pay.app.merchant.ext.impl.haike.constant.HaikePayConstant;
import com.hlkj.pay.app.merchant.ext.impl.haike.constant.HttpClientHelper;
import com.hlkj.pay.app.merchant.ext.impl.haike.constant.SignUtils;
import com.hlkj.pay.app.merchant.ext.impl.haike.dto.HaikeAccessAuthDto;
import com.hlkj.pay.app.merchant.ext.impl.haike.dto.HaikePayConfig;
import com.hlkj.pay.app.merchant.ext.impl.haike.dto.resp.HaikeAccessQueryResp;
import com.hlkj.pay.app.merchant.ext.impl.haike.dto.resp.HaikePicUploadResp;
import com.hlkj.pay.app.merchant.ext.impl.haike.dto.resp.HaikeTerminalResp;
import com.hlkj.pay.app.merchant.ext.impl.leshua.constant.XmlUtils;
import com.hlkj.pay.common.PayResultCode;
import com.hlkj.pay.dto.merchant.MerchantAccessDto;
import com.hlkj.pay.dto.merchant.MerchantAccessScene;
import com.hlkj.pay.dto.merchant.ProviderChannelFeeConfigList;
import com.hlkj.pay.dto.provider.StepFeeConfig;
import com.hlkj.pay.enums.MerchantEnum;
import com.hlkj.pay.enums.PayEnums;
import com.hlkj.pay.infrastructure.model.merchant.MerchantAccessInfoDO;
import com.hlkj.pay.infrastructure.model.order.PayOrderDO;
import com.hlkj.pay.infrastructure.model.pay.PayWayDO;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;
import com.hlkj.pay.service.merchant.IMerchantAccessService;
import com.hlkj.pay.service.merchant.IMerchantConfigService;
import com.hlkj.pay.service.order.IPayOrderService;
import com.hlkj.pay.service.pay.IPayChannelService;
import com.hlkj.pay.service.pay.IPayWayService;
import com.hlkj.pay.util.ImageUtils;

import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 海科服务商 商户进件参数处理
 *
 * @author HlpayTeam
 * @date 2024/09/26 12:02
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class HaikePayCommonParamsHandle {

    private final UploadServiceImpl uploadService;

    private final RedisTemplateService redisTemplateService;

    private final IPayOrderService payOrderService;

    private final IPayWayService payWayService;

    private final IMerchantConfigService merchantConfigService;

    private final IPayChannelService payChannelService;

    private final IMerchantAccessService merchantAccessService;

    private static HttpClientHelper httpClientHelper = new HttpClientHelper();


    /**
     * 获取费率信息
     * @param merchantFeeConfigList
     * @param payType
     * @param sceneType
     * @param more1000  是否大于1000
     * @return
     */
    public Integer getRateUnit(List<ProviderChannelFeeConfigList> merchantFeeConfigList,PayEnums.PAY_TYPE payType,PayEnums.SCENE_TYPE sceneType, boolean more1000){

        ProviderChannelFeeConfigList feeConfig = null;
        // 过滤 支付类型
        Predicate<ProviderChannelFeeConfigList> isPayType = merchantFeePayConfig -> merchantFeePayConfig.getPayWayDO().getType()  == payType.getCode();
        // 过滤 支付场景
        Predicate<ProviderChannelFeeConfigList> isSceneType = merchantFeeSceneConfig -> merchantFeeSceneConfig.getPayWayDO().getSceneType()  == sceneType.getCode();
        // 过滤并排序
        List<ProviderChannelFeeConfigList> merchantFeeConfigMap = merchantFeeConfigList.stream().filter(isPayType.and(isSceneType)).collect(Collectors.toList());

        Integer fee = 0;

        switch (payType){
            case WECHAT:
            case ALIPAY:
                // 取百分比最高的值
                merchantFeeConfigMap = merchantFeeConfigMap.stream().sorted(Comparator.comparing(merchantFeeSceneConfig -> merchantFeeSceneConfig.getDefaultFeeConfigValue().getRateBase())).collect(Collectors.toList());
                feeConfig = CollUtil.getLast(merchantFeeConfigMap);
                // 默认百分比
                if(feeConfig == null){
                    fee = 38;
                }else{
                    BigDecimal rateBase =  feeConfig.getDefaultFeeConfigValue().getRateBase();
                    if(rateBase == null){
                        rateBase = new BigDecimal(0.38);
                    }else if(rateBase.doubleValue() <= 0.38){
                        rateBase = new BigDecimal(0.38);
                    }
                    fee = rateBase.multiply(new BigDecimal(100)).intValue();
                }
                break;
            case UNION_APY:
                merchantFeeConfigMap = merchantFeeConfigMap.stream().filter(merchantFeeSceneConfig ->  StrUtil.containsIgnoreCase(merchantFeeSceneConfig.getPayWayDO().getCode(),"Union")).collect(Collectors.toList());
                if(CollUtil.isNotEmpty(merchantFeeConfigMap)){
                    feeConfig = merchantFeeConfigMap.get(0);
                }
                // >1000
                if(more1000){
                    // 阶梯费率
                    if(feeConfig == null){
                        fee = 52;
                    }else{
                        Optional<StepFeeConfig> optional = feeConfig.getStepFeeConfigs().stream().filter(stepFeeConfig -> stepFeeConfig.getEndAmt().intValue() > 1000).findFirst();
                        if(optional.isPresent() && optional.get().getRateBase() != null && optional.get().getRateBase().doubleValue() > 0.51){
                            fee = optional.get().getRateBase().multiply(new BigDecimal(100)).intValue();
                        }else{
                            fee = 52;
                        }
                    }
                    // <1000
                }else{
                    // 阶梯费率
                    if(feeConfig == null){
                        fee = 24;
                    }else{
                        Optional<StepFeeConfig> optional = feeConfig.getStepFeeConfigs().stream().filter(stepFeeConfig -> stepFeeConfig.getEndAmt().intValue() <= 1000).findFirst();
                        if(optional.isPresent() && optional.get().getRateBase() != null && optional.get().getRateBase().doubleValue() > 0.23){
                            fee = optional.get().getRateBase().multiply(new BigDecimal(100)).intValue();
                        }else{
                            fee = 24;
                        }
                    }
                }

                break;

        }
        return fee;
    }


    public String getTerminalNo(MerchantAccessInfoDO merchantAccessInfo, HaikePayConfig haikePayConfig){
        try{
            Map<String,Object> data = new HashMap<>();
            data.put("agent_no",haikePayConfig.getFtpName());
            data.put("agent_apply_no",IdUtil.fastSimpleUUID());
            data.put("merch_no",merchantAccessInfo.getSubMchId());
            data.put("sn", IdUtil.fastSimpleUUID());
            data.put("code", "11");

            // 获取经营地址
            MerchantAccessDto merchantAccessDto = merchantAccessService.domainDetailByRequestId(merchantAccessInfo.getRequestId());
            data.put("terminal_address", merchantAccessDto.getMerchantAccessBusiness().getAddress());

            log.info("海科商户终端绑定 请求参数:{}", JSONUtil.toJsonStr(data));
            String response = requestPostApi(HaikePayConstant.MER_TERMINAL_BIND_URL,data,haikePayConfig);
            log.info("海科商户终端绑定 返回参数:{}", response);
            HaikeTerminalResp terminalResp = JSONUtil.toBean(response,HaikeTerminalResp.class);
            return terminalResp.getPn();
        }catch (Exception e){
            e.printStackTrace();
            log.info("海科商户终端绑定 请求失败:{}", e.getMessage());
        }
        return null;
    }


    /**
     * 开通结算产品信息
     * @param merchantFeeConfigList  费率信息
     * @param corporate  是否对公
     * @return
     */
    public Map<String,Object> getSettleProductInfo(List<ProviderChannelFeeConfigList> merchantFeeConfigList, boolean corporate){

        Map<String,Object> settle_data = new HashMap<>();

        List<ProviderChannelFeeConfigList> settlementInfos = new ArrayList<>();

        // 支付类型分组
        Map<Integer, List<ProviderChannelFeeConfigList>> merchantFeeConfigMap = merchantFeeConfigList.stream()
                .filter(merchantFeeConfig -> merchantFeeConfig.getPayWayDO() != null)
                .collect(Collectors.groupingBy(merchantFeeConfig -> merchantFeeConfig.getPayWayDO().getType()));
        for (Map.Entry<Integer, List<ProviderChannelFeeConfigList>> entry : merchantFeeConfigMap.entrySet()) {
            switch (PayEnums.PAY_TYPE.fromByCode(entry.getKey())) {
                case FUNCTION:
                    for(ProviderChannelFeeConfigList feeConfig:entry.getValue()){
                        if(feeConfig.getStatus() == 1){
                            settlementInfos.add(feeConfig);
                        }
                    }
                    break;
            }

            // 结算费率
            if(CollUtil.isNotEmpty(settlementInfos)){
                // 过滤D0 只能选一种,按优先顺序取
                Optional<ProviderChannelFeeConfigList> feeConfig_OTHER = settlementInfos.stream().filter(conf -> Objects.equals(conf.getPayWayDO().getCode(),MerchantEnum.SETTLE_CYCLE.D0.getPayWayCode())).findFirst();
                // D0
                if(feeConfig_OTHER.isPresent()){
                    settle_data.put("settlement_cycle","D0");
                    settle_data.put("withdrawal_rate",feeConfig_OTHER.get().getDefaultFeeConfigValue().getRateBase().toString());
                    settle_data.put("withdrawal_feemin",feeConfig_OTHER.get().getDefaultFeeConfigValue().getFixedRate().toString());
                    if(corporate){
                        settle_data.put("public_withdrawal_rate",feeConfig_OTHER.get().getDefaultFeeConfigValue().getRateBase().toString());
                        settle_data.put("public_withdrawal_feemin",feeConfig_OTHER.get().getDefaultFeeConfigValue().getFixedRate().toString());
                    }
                }else{
                    // D1 默认固定值 0
                    feeConfig_OTHER = settlementInfos.stream().filter(conf -> Objects.equals(conf.getPayWayDO().getCode(),MerchantEnum.SETTLE_CYCLE.D1.getPayWayCode())).findFirst();
                    if(feeConfig_OTHER.isPresent()){
                        settle_data.put("settlement_cycle","D1");
                        settle_data.put("withdrawal_rate",feeConfig_OTHER.get().getDefaultFeeConfigValue().getRateBase().toString());
                        settle_data.put("withdrawal_feemin",feeConfig_OTHER.get().getDefaultFeeConfigValue().getFixedRate().toString());
                        if(corporate){
                            settle_data.put("public_withdrawal_rate",feeConfig_OTHER.get().getDefaultFeeConfigValue().getRateBase().toString());
                            settle_data.put("public_withdrawal_feemin",feeConfig_OTHER.get().getDefaultFeeConfigValue().getFixedRate().toString());
                        }
                    }else{
                        // T1
                        feeConfig_OTHER = settlementInfos.stream().filter(conf -> Objects.equals(conf.getPayWayDO().getCode(),MerchantEnum.SETTLE_CYCLE.T1.getPayWayCode())).findFirst();
                        if(feeConfig_OTHER.isPresent()){
                            settle_data.put("settlement_cycle","T1");
                            settle_data.put("withdrawal_rate","0");
                            settle_data.put("withdrawal_feemin","0");
                            if(corporate){
                                settle_data.put("public_withdrawal_rate","0");
                                settle_data.put("public_withdrawal_feemin","0");
                            }
                        }
                    }
                }
            }
        }
        return settle_data;
    }


    public CommonResult<HaikePayConfig> haikePayConfig(ProviderChannelConfigDO providerChannelConfigDO, boolean test) {
        String paramsConfig = providerChannelConfigDO.getParamsConfig();
        if (StringUtils.isEmpty(paramsConfig)) {
            return CommonResult.error(PayResultCode.PAY_CHANNEL_CONFIG_NOT_EXITS);
        }
        // 配置转换
        HaikePayConfig haikePayConfig = null;
        try {
            haikePayConfig = JsonUtils.parseObject(paramsConfig, HaikePayConfig.class);
            return CommonResult.success(haikePayConfig);
        }
        catch (Exception e) {
            String format = String.format(PayResultCode.PAY_CHANNEL_CONFIG_ERROR.getMsg(), "海科");
            return CommonResult.error(PayResultCode.PAY_CHANNEL_CONFIG_NOT_EXITS.getCode(), format);
        }
    }






    public Integer licenseType(String code) {
        if (!StringUtils.hasText(code)) {
            return null;
        }
        // 营业执照类型：
        // 1：营业执照
        // 2：营业执照(多证合一)
        // 3：事业单位法人证书
        // 4：社会团体法人登记证书
        // 5：民办非企业单位登记证书
        // 6：基金会法人登记证书
        // 7：宗教活动场所登记证
        // 8：其他证书/批文/证明
        // 9：执业许可证/执业证
        // 10：基层群众性自治组织特别法人统一社会信用代码证
        // 11：农村集体经济组织登记证
        // 12：业主委员会备案证明

        /**
         * 10A\10B默认0, 10E\10F默认为1, 10D默认为2
         * 0、营业执照（10A\10B可选）
         * 1、统一社会信用代码证（10E\10F可选）
         * 2、事业单位法人证书（10D可选）
         * 3、社会团体法人登记证书（10F可选）
         * 4、民办非企业单位登记证书（10F可选）
         * 5、基金会法人登记证书（10F可选）
         * 6、宗教活动场所登记证（10F可选）
         * 7、政府部门下发的其他有效证明文件（10F可选）
         * 8、执业许可证/执业证（10F可选）
         * 9、基层群众性自治组织特别法人统一社会信用代码证（10F可选）
         * 10、农村集体经济组织登记证（10F可选）
         */
        switch (code) {
            case "1":
            case "2":
                return 0;
            case "3":
                return 2;
            case "4":
                return 3;
            case "5":
                return 4;
            case "6":
                return 5;
            case "7":
                return 6;
            case "9":
                return 8;
            case "10":
                return 9;
            case "11":
                return 10;
            default:
                return 0;
        }
    }

    public Integer certType(String code) {
        if (!StringUtils.hasText(code)) {
            return null;
        }
        // 营业执照类型：
        // 1:身份证
        // 2:护照
        // 3:军官证
        // 4:士兵证
        // 5:回乡证
        // 6:户口本
        // 7:外国护照
        // 8:其他
        // 9:暂住证
        // 10:警官证
        // 11:文职干部证
        // 12:港澳台同胞通行证
        // 13:外国人居留证
        // 14:台胞证
        // 15:港澳台居住证
        // 16：营业执照 （只有部分场景才会用到 如 受益人和股东）
        /**
         1:身份证（小微商户上送个人证件类型）
         2:中国香港居民-来往内地通行证
         3:为其他国家或地区居民-护照
         4:中国澳门居民-来往内地通行证
         5:中国台湾居民-来往大陆通行证
         10：外国人永久居留身份证
         11：港澳居民居住证
         12：台湾居民居住证
         13：执行事务合伙人
         其中2、3、4、5、10、11、12、支持对公和对私法人结算，不允许入网小微商户
         */
        switch (code) {
            case "1":
                return 1;
            case "7":
                return 3;
            case "13":
                return 10;
            default:
                return 1;
        }
    }

    /**
     * 海科进件主体类型
     * 10A:个体工商户
     * 10B:企业
     * 10C:小微商户
     * 10D:事业单位
     * 10E:政府机构
     * 10F:社会组织

     * 系统主体类型
     * 1：政府机构
     * 2：国营企业
     * 3：私营企业
     * 4：外资企业
     * 5：个体工商户
     * 6：其它组织
     * 7：事业单位
     * 8：业主委员会；
     */
    public String companyType(Integer type, MerchantEnum.MERCHANT_TYPE merchantType) {
        // 小微企业
        if(merchantType == MerchantEnum.MERCHANT_TYPE.PERSONAL){
            return "10C";
        }
        // 企业
        String companyType = null;
        switch (type){
            case 5:
                companyType = "10A";
                break;
            case 1:
                companyType = "10E";
                break;
            case 2:
            case 3:
            case 4:
                companyType = "10B";
                break;
            case 8:
            case 6:
                companyType = "10F";
                break;
            case 7:
                companyType = "10D";
                break;
        }

        return companyType;
    }


    /**
     * 过去指定场景类型的数据
     * @param sceneList
     * @param senceType
     * @return
     */
    public  MerchantAccessScene getMerchantAccessSceneValue(List<MerchantAccessScene> sceneList, Integer senceType){
        if(CollUtil.isNotEmpty(sceneList)){
            for(MerchantAccessScene accessScene:sceneList){
                if(accessScene.getType() == senceType){
                    return accessScene;
                }
            }

        }
        return null;
    }


    /**
     * 海科上传图片获取merQualUrl
     * @param key  key值 用于错误提示
     * @param filePath  本地路劲/https
     * @param haikePayConfig
     * @return
     */
    public String getUploadMerQualUrl(String key,String filePath, HaikePayConfig haikePayConfig) {

        String errorMsg = "海科 Upload 上传文件格式异常 , "+key+ " is null";
        if(StrUtil.isEmpty(filePath)){
            log.error(errorMsg);
            throw new RuntimeException(errorMsg);
        }

        File file = null;
        if(HttpUtil.isHttp(filePath)  || HttpUtil.isHttps(filePath) ){
            // 创建临时文件
            file =  FileUtil.createTempFile("."+ ImageUtils.getFileExtension(filePath),true);
            // 文件流copy到临时文件
            HttpUtil.downloadFile(filePath,file);
        }else{
            file = FileUtil.newFile(filePath);
        }

        if(FileUtil.isEmpty(file)){
            log.error(errorMsg);
            throw new RuntimeException(errorMsg);
        }

        String result = uploadPicApi(file,haikePayConfig);
        log.info("海科 Upload 上传文件 filePath :{}, 配置 :{}, 返回参数 :{}",filePath, JSONUtil.toJsonStr(haikePayConfig),result);
        if(StrUtil.isNotEmpty(result)){
            HaikePicUploadResp picUploadResp = JSONUtil.toBean(result,HaikePicUploadResp.class);
            return picUploadResp.getImage_id();
        }else{
            throw new RuntimeException("海科 Upload 上传文件异常 : "+filePath);
        }
    }


    /**
     * 获取支付方式
     * @param payWayDO
     * @return
     */
    public String getPayWay(PayWayDO payWayDO){
        String payway = null;
        // 支付渠道枚举
        PayEnums.SCENE_PAY_TYPE scenePayType = PayEnums.SCENE_PAY_TYPE.from(payWayDO.getSubType());
        // 支付方式枚举
        PayEnums.PAY_TYPE payType = PayEnums.PAY_TYPE.fromByCode(payWayDO.getType());
        switch (payType){
            case WECHAT:
                payway = "WX";
                break;
            case ALIPAY:
                payway = "ALI";
                break;
            case UNION_APY:
                payway = "UNIONQR";
                break;
        }
        return payway;
    }


    /**
     * 获取支付场景
     * @param payWayDO
     * @return
     */
    public String getPayScene(PayWayDO payWayDO){
        String scene = null;
        PayEnums.SCENE_TYPE sceneType = PayEnums.SCENE_TYPE.from(payWayDO.getSceneType());
        switch (sceneType){
            case OFFLINE:
                scene = "OFFLINE";
                break;
            case ONLINE:
                scene = "ONLINE";
                break;
        }
        return scene;
    }


    public PayOrderDO queryPayOrder(String orderId){
        return payOrderService.queryPayOrderNoCache(orderId);
    }

    /**
     * 时间戳转DateTime
     * @param timestamp
     * @return
     */
    public long formatTimestamp(long timestamp,boolean minute){
        long second = (timestamp-System.currentTimeMillis())/1000;
        if(minute){
            return second/60;
        }
        return second;
    }





    /**
     * 获取商户号
     * @param haikePayConfig
     * @param payType  微信/支付宝
     * @return
     */
    public HaikeAccessAuthDto getMchId(HaikePayConfig haikePayConfig, String subMchId, PayEnums.PAY_TYPE payType){

        HaikeAccessAuthDto authDto = new HaikeAccessAuthDto();

        Map<String,Object> data = new HashMap<>();
        data.put("agent_no",haikePayConfig.getFtpName());
        data.put("merch_no",subMchId);
        String response = requestPostApi(HaikePayConstant.AUDIT_QUERY_URL,data,haikePayConfig);
        // 参数转化
        HaikeAccessQueryResp accessResp = JSONUtil.toBean(response,HaikeAccessQueryResp.class);
        switch (payType){
            case WECHAT:
                log.info("海科查询微信商户号 返回参数:{}", response);
                if(HaikePayConstant.OK.equals(accessResp.getReturn_code())){
                    if(accessResp.getWx_biz_info() != null){
                        authDto.setSubMcuId(accessResp.getWx_biz_info().getWxsub_merch_no());
                        authDto.setReportStatus(accessResp.getWx_biz_info().getReport_status());
                        authDto.setChannelNo(accessResp.getWx_biz_info().getChannel_no());
                        return authDto;
                    }
                }
                break;
            case ALIPAY:
                log.info("海科查询支付宝商户号 返回参数:{}", response);
                if(HaikePayConstant.OK.equals(accessResp.getReturn_code())){
                    if(accessResp.getAli_biz_info() != null){
                        authDto.setSubMcuId(accessResp.getAli_biz_info().getAlisub_merch_no());
                        authDto.setReportStatus(accessResp.getAli_biz_info().getReport_status());
                        authDto.setChannelNo(accessResp.getAli_biz_info().getChannel_no());
                        return authDto;
                    }
                }
                break;
        }
        return null;
    }


    /**
     * 回调签名校验
     * @param request
     * @param haikePayConfig
     * @return
     * @throws Exception
     */
    public String decrypt(HttpServletRequest request, HaikePayConfig haikePayConfig,boolean checkSign) throws Exception {
        // 获取响应内容
        String responseText = XmlUtils.getContentFromRequestInputStream(request);
        if (StrUtil.isEmpty(responseText)) {
            return null;
        }
        Map<String,Object> respData = JSONUtil.toBean(responseText,Map.class);
        // 获取响应数据签名
        String oldSign = MapUtil.getStr(respData,"sign");
        //获取新签名值
        String newSign = SignUtils.signParams(haikePayConfig.getAccessKey(),respData);
        log.info("MD5签名原始串：{}，签名结果：{}", oldSign, newSign);
        if(checkSign){
            if(!oldSign.equalsIgnoreCase(newSign)){
                log.info("签名校验失败！");
                return null;
            }
        }
        return responseText;
    }

    public static  String requestPostApi(String url,Map<String,Object> params, HaikePayConfig haikePayConfig){
        // accessid
        params.put("accessid",haikePayConfig.getAccessId());
        // 拼接字符串
        String str2Sign = SignUtils.signParams(haikePayConfig.getAccessKey(),JSONUtil.toBean(JSONUtil.toJsonStr(params), Map.class));
        params.put("sign",str2Sign);
        //获取签名值
        log.info("签名结果：{}, 请求参数：{}", str2Sign,params);
        String result = httpClientHelper.post(url,JSONUtil.toJsonStr(params),HttpClientHelper.ACCEPT_TYPE_JSON);
        return result;
    }


    /**
     * 上传图片
     * @param file
     * @param haikePayConfig
     * @return
     */
    public static String uploadPicApi(File file, HaikePayConfig haikePayConfig){

        Map<String,Object> data = new HashMap<>();
        String base64Str = null;
        try {
            // 读取图片文件为byte数组
            base64Str = Base64Encoder.encode(FileUtil.readBytes(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.put("image",base64Str);
        String result = requestPostApi(HaikePayConstant.PIC_UPLOAD_URL,data,haikePayConfig);
        return result;
    }




    public static void main(String[] args) {
        HaikePayConfig haikePayConfig = new HaikePayConfig();
        haikePayConfig.setAccessId("40288098961a6727019623c5e82114b1");
        haikePayConfig.setAccessKey("c7208f45cc514f9980140216924bd6ad");
        String img = "E:/cert/gift_8.png";
        //图片
        String result = uploadPicApi(FileUtil.newFile(img),haikePayConfig);
        System.out.println(result);

        Map<String,String> params = new HashMap<>();
        params.put("service","query_status");
        params.put("merchant_id","111");
        params.put("third_order_id","M11111");

        System.out.println(IdUtils.getSnowflakeNextIdStr());
        System.out.println(IdUtils.getSnowflakeNextIdStr().length());
    }


}
